import com.blogSystem.type.TypeApplication;
import com.blogSystem.type.dao.TypeMapper;
import com.blogSystem.type.pojo.Type;
import com.blogSystem.type.service.TypeService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import util.IdWorker;
import util.SetPriority;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = TypeApplication.class)

public class test {
    @Autowired
    private TypeMapper typeMapper;
    @Autowired
    private IdWorker idWorker;

    @Autowired
    private TypeService typeService;
    @Test
    public void test() throws UnknownHostException {
/*
        Type type1=new Type(idWorker.nextId()+"","游戏");
        Type type2=new Type(idWorker.nextId()+"","影视");
        Type type3=new Type(idWorker.nextId()+"","兴趣");
        Type type4=new Type(idWorker.nextId()+"","生活");
        Type type5=new Type(idWorker.nextId()+"","轻小说");
        Type type6=new Type(idWorker.nextId()+"","科技");
        Type type7=new Type(idWorker.nextId()+"","动画");
        List<Type> list = new ArrayList<Type>();
        list.add(type1);
        list.add(type2);
        list.add(type3);
        list.add(type4);
        list.add(type5);
        list.add(type6);
        list.add(type7);
        for(Type type:list){
            typeMapper.insert(type);

        }
*/
//Type type=typeService.saveType("1","病毒是一种个体微小，结构简单，只含一种核酸（DNA或RNA），必须在活细胞内寄生并以复制方式增殖的非细胞型生物。病毒是一种非细胞生命形态，它由一个核酸长链和蛋白质外壳构成，病毒没有自己的代谢机构，没有酶系统");

        //System.out.println(type.getId()+"        "+type.getType());


        InetAddress addr = InetAddress.getLocalHost();
        System.out.println("Local HostAddress:"+addr.getHostAddress());
                String hostname = addr.getHostName();
        System.out.println("Local host name: "+hostname);

    }
    @Test
    public void count(){
        Type type1=new Type("1","1");
        Type type2=new Type("2","1");
        Type type3=new Type("3","1");
        Type type4=new Type("4","1");
        List <Type> list=new ArrayList<Type>();
        list.add(type1);
        list.add(type2);
        list.add(type3);
        list.add(type4);
        PriorityQueue priorityQueue=new PriorityQueue();

        for(Type type:list){
            SetPriority<Type> typeSetPriority=new SetPriority<Type>();
            if("1".equals(type.getId())){
                typeSetPriority.setObject(type);
                typeSetPriority.addPriorityLevel1(1);
                priorityQueue.add(typeSetPriority);
            }
            if("2".equals(type.getId())){

                typeSetPriority.setObject(type);
                typeSetPriority.addPriorityLevel2(1);
                priorityQueue.add(typeSetPriority);
            }
            if("3".equals(type.getId())){
                typeSetPriority.setObject(type);
                typeSetPriority.addPriorityLevel3(1);
                priorityQueue.add(typeSetPriority);
            }
            if("4".equals(type.getId())){
                typeSetPriority.setObject(type);
                typeSetPriority.declinePriorityLevel1(1);
                priorityQueue.add(typeSetPriority);
            }
        }

        for(int j = 0; j < list.size(); j++) {
            SetPriority setPriority=(SetPriority)priorityQueue.remove();
            Type type= (Type) setPriority.getObject();

            System.out.println(type.getId());
        }
    }
}
